package com.dlc.garbagerecyclebox.bean;


import com.dlc.commonbiz.base.serialport.utils.ByteUtil;

/**
 * @author :      fangbingran
 * @aescription : todo(这里用一句话描述这个类的作用)
 * @date :        2019/07/27  18:58
 */
public class CmdGarbageRecyclerCmdBean {


    public static CmdGarbageRecyclerCmdBean.Builder newBuilder() {
        return new CmdGarbageRecyclerCmdBean.Builder();
    }

    public static class Builder {
        /***
         * 帧头(2字节)
         * 协议版本号
         * 设备地址
         * 命令码
         * 命令流水号
         * 内容长度
         * 内容
         * 校验码
         * */
        /**
         * 帧头
         */
        String frameHeader;
        /**
         * 协议版本
         */
        String protocolVersion;
        /**
         * 目标地址
         */
        String destinationAddress;
        /**
         * 命令码
         */
        String command;
        /**
         * 命令码流水号
         */
        String commandNumber;
        /**
         * 数据长度
         */
        String dataLength;

        /**
         * 数据域
         */
        String data;
        /**
         * 校验码
         */
        String cRC;


        public String getProtocolVersion() {
            return protocolVersion;
        }

        public Builder setProtocolVersion(String protocolVersion) {
            this.protocolVersion = protocolVersion;
            return this;
        }

        public String getFrameHeader() {
            return frameHeader;
        }

        public Builder setFrameHeader(String frameHeader) {
            this.frameHeader = frameHeader;
            return this;
        }


        public String getDestinationAddress() {
            return destinationAddress;
        }

        public Builder setDestinationAddress(String destinationAddress) {
            this.destinationAddress = destinationAddress;
            return this;
        }

        public String getDataLength() {
            return dataLength;
        }

        public Builder setDataLength(String dataLength) {
            this.dataLength = dataLength;
            return this;
        }

        public String getCommand() {
            return command;
        }

        public Builder setCommand(String command) {
            this.command = command;
            return this;
        }

        public String getCommandNumber() {
            return commandNumber;
        }

        public Builder setCommandNumber(String commandNumber) {
            this.commandNumber = commandNumber;
            return this;
        }

        public String getData() {
            return data;
        }

        public Builder setData(String data) {
            this.data = data;
            return this;
        }

        public String getCRC() {
            return cRC;
        }

        public Builder setCRC(String cRC) {
            this.cRC = cRC;
            return this;
        }


        @Override
        public String toString() {
            return "" +
                    "帧头='" + frameHeader + '\'' +
                    ", 协议版本='" + protocolVersion + '\'' +
                    ", 设备地址='" + destinationAddress + '\'' +
                    ", 命令码='" + command + '\'' +
                    ", 命令流水号='" + commandNumber + '\'' +
                    ", 数据长度='" + dataLength + '\'' +
                    ", 数据域='" + data + '\'' +
                    ", 校验码(异或)='" + cRC + '\'' +
                    '}';
        }

        public byte[] build() {
            /**按次序拼接, 帧头,协议版本号,设备地址, 命令码,命令流水号, 命令码,数据长度,数据域,校验码*/
            String stringBuilder = frameHeader +
                    protocolVersion +
                    destinationAddress +
                    command +
                    commandNumber +
                    dataLength +
                    data +
                    cRC;
            return ByteUtil.hexStr2bytes(stringBuilder);
        }
    }

}
